import { constantRoutes, asyncRoutes } from '@/router'

const state = {
  routes: []
}
const mutations = {
  // 4.解决菜单显示问题
  setRoutes(state, filterRoutes) {
    state.routes = [
      ...constantRoutes,
      ...filterRoutes
    ]
  }
}
const actions = {
  // 2.过滤路由
  onFilterRoutes(context, menus) {
    const filterRoutes = asyncRoutes.filter(t => menus.includes(t.name))
    // 测试代码
    // const filterRoutes = asyncRoutes
    context.commit('setRoutes', filterRoutes)
    return filterRoutes // 第三步使用
  }
}

export default {
  state,
  namespaced: true,
  mutations,
  actions
}
